package com.shinechain.controller;

import com.shinechain.botModel.WorkBot;
import com.shinechain.dao.*;
import com.shinechain.domain.*;
import com.shinechain.model.*;

import com.shinechain.model.SendMsgOnTimeReq;
import com.shinechain.service.user.impl.ProjectBotImpl;
import com.shinechain.service.user.impl.WorkBotService;
import com.shinechain.utils.FileUtils;
import com.shinechain.utils.POIUtil;


import com.shinechain.utils.RewardUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

import java.io.*;

import java.nio.charset.Charset;
import java.util.*;

@Controller
@RequestMapping(value = "botApi")
public class WorkBotController implements ApplicationListener<ContextRefreshedEvent> {
    private static Logger logger = org.apache.log4j.Logger.getLogger(WorkBotController.class);
    String fileName;


    public static String imgPath;
    @Autowired
    WorkBotService workBotService;

    @Autowired
    BlackKeyListMapper blackKeyListMapper;

    @Autowired
    WhiteKeyListMapper whiteKeyListMapper;

    @Autowired
    WorkBotChatMapper workBotChatMapper;

    @Autowired
    WorkBotInfoMapper workBotInfoMapper;

    @Autowired
    InviteRewardMapper inviteRewardMapper;

    @Autowired
    UsersMapper usersMapper;

    @Autowired
    RewardMapper rewardMapper;

    @Autowired
    RewardUserMapper rewardUserMapper;

    @Autowired
    GuessMapper guessMapper;

    @Autowired
    GuessUserMapper guessUserMapper;

    @Autowired
    TelegramUserMapper telegramUserMapper;

    @Autowired
    CheckInMapper checkInMapper;

    @Autowired
    ChatTokenMapper chatTokenMapper;

    @RequestMapping(value = "botMethod")
    @ResponseBody
    public BotMethodResp function(HttpServletRequest request) {
        //反射获取类变量
        String botMethod = request.getParameter("botMethod");
        BotMethodResp botMethodResp = new BotMethodResp();

        if (botMethod != null && !botMethod.equals("")) {
            if (!BotMethodSwitch.botMethod.containsKey(botMethod)) {
                botMethodResp.setStatus(400);
                botMethodResp.setErrorMsg("不存在此方法");
                return botMethodResp;
            }
        } else {
            botMethodResp.setStatus(400);
            botMethodResp.setErrorMsg("请求方法为空");
            return botMethodResp;
        }
        //关闭或开启
        boolean isopen = BotMethodSwitch.botMethod.get(botMethod);
        BotMethodSwitch.botMethod.put(botMethod, !isopen);
        botMethodResp.setStatus(200);
        botMethodResp.setBotMethod(!isopen);
        workBotService.updateDaoWorkBotInfo();
        logger.debug("请求方法" + botMethod + " 状态:" + BotMethodSwitch.botMethod.get(botMethod));
        return botMethodResp;
    }

    @RequestMapping(value = "sendMsgOnTime")
    @ResponseBody
    public SendMsgOnTimeResp sendMsgOnTime(@RequestBody SendMsgOnTimeReq sendMsgOnTimeReq) {
        SendMsgOnTimeResp sendMsgOnTimeResp = new SendMsgOnTimeResp();
        if (!BotMethodSwitch.botMethod.get("useSendMsgOnTime")) {
            sendMsgOnTimeResp.setStatus(400);
            sendMsgOnTimeResp.setErrorMsg("您还没有开启此服务");
            return sendMsgOnTimeResp;
        }
        if (sendMsgOnTimeReq.getSendMsgOnTime() > 0 &&
                sendMsgOnTimeReq.getSendMsgOnTimeStr() != null &&
                !sendMsgOnTimeReq.getSendMsgOnTimeStr().equals("") &&
                sendMsgOnTimeReq.getSendMsgStartMin() >= 0) {
            try {
                BotMethodSwitch.sendMsgStartMin = sendMsgOnTimeReq.getSendMsgStartMin();
                BotMethodSwitch.sendMsgOnTime = sendMsgOnTimeReq.getSendMsgOnTime();
                BotMethodSwitch.sendMsgOnTimeStr = sendMsgOnTimeReq.getSendMsgOnTimeStr();
                BotMethodSwitch.sendMsgTimes = sendMsgOnTimeReq.getSendMsgTimes();
                //开启自动说话功能
                workBotService.updateDaoWorkBotInfo();
                sendMsgOnTimeResp.setStatus(200);
                sendMsgOnTimeResp.setSendMsgOnTime(BotMethodSwitch.sendMsgOnTime);
                sendMsgOnTimeResp.setSendMsgOnTimeStr(BotMethodSwitch.sendMsgOnTimeStr);
                sendMsgOnTimeResp.setSendMsgStartMin(BotMethodSwitch.sendMsgStartMin);
                sendMsgOnTimeResp.setSendMsgTimes(BotMethodSwitch.sendMsgTimes);
                logger.debug("开启自动说话");
                return sendMsgOnTimeResp;
            } catch (Exception e) {
                e.printStackTrace();
                sendMsgOnTimeResp.setStatus(400);
                sendMsgOnTimeResp.setErrorMsg("系统错误");
                return sendMsgOnTimeResp;
            } finally {
                ProjectBotImpl.getWorkBot().run();
            }
        }
        sendMsgOnTimeResp.setStatus(400);
        sendMsgOnTimeResp.setErrorMsg("输入参数有误");
        return sendMsgOnTimeResp;
    }

    @RequestMapping(value = "token")
    @ResponseBody
    public TokenResp token(@RequestBody TokenReq tokenReq) {
        TokenResp tokenResp = new TokenResp();
        if (tokenReq != null && tokenReq.getToken() >= 0 && tokenReq.getTokenDayTimes() >= -1) {
            try {
                BotMethodSwitch.token = tokenReq.getToken();
                BotMethodSwitch.tokenDayTimes = tokenReq.getTokenDayTimes();
                workBotService.updateDaoWorkBotInfo();

                tokenResp.setStatus(200);
                tokenResp.setToken(BotMethodSwitch.token);
                tokenResp.setTokenDayTimes(BotMethodSwitch.tokenDayTimes);
                return tokenResp;
            } catch (Exception e) {
                logger.debug("token出错", e);
                tokenResp.setStatus(500);
                tokenResp.setErrorMsg("token系统出错");
            }

        } else {
            tokenResp.setStatus(400);
            tokenResp.setErrorMsg("输入参数有误");
            logger.debug("输入参数有误");
            return tokenResp;
        }
        tokenResp.setStatus(500);
        tokenResp.setErrorMsg("系统出错");
        logger.debug("系统出错");
        return tokenResp;
    }

    @RequestMapping(value = "getSendToken")
    @ResponseBody
    public SendTokenResp sendTokenResp() {
        SendTokenResp sendTokenResp = new SendTokenResp();
        List<InviteReward> list = inviteRewardMapper.findAll();
        HashMap<Integer, InviteRewardCount> inviterRewardCount = new HashMap<>();
        InviteRewardCount inviteRewardCount;
        for (int i = 0; i < list.size(); i++) {
            inviteRewardCount = new InviteRewardCount();
            //没有找到
            if (!inviterRewardCount.containsKey(list.get(i).getInviterid())) {
                inviteRewardCount.setInviteCount(1);
                inviteRewardCount.setTelegrameId(list.get(i).getInviterid());   //id
                inviteRewardCount.setTokenCount(list.get(i).getToken());
                inviteRewardCount.setTelegramName(list.get(i).getInvitername()); //昵称
                inviterRewardCount.put(list.get(i).getInviterid(), inviteRewardCount);
            } else {
                inviteRewardCount = inviterRewardCount.get(list.get(i).getInviterid());
                inviteRewardCount.setTokenCount(inviteRewardCount.getTokenCount() + list.get(i).getToken());
                inviteRewardCount.setInviteCount(inviteRewardCount.getInviteCount() + 1);
            }
        }
        sendTokenResp.setInviterRewardCount(inviterRewardCount);
        sendTokenResp.setUseToken(BotMethodSwitch.botMethod.get("useTokenSay"));
        sendTokenResp.setToken(BotMethodSwitch.token);
        sendTokenResp.setTokenDayTimes(BotMethodSwitch.tokenDayTimes);
        sendTokenResp.setStatus(200);
        return sendTokenResp;
    }

    @RequestMapping(value = "chat", method = RequestMethod.POST)
    @ResponseBody
    public ChatResp chat(@RequestParam("file") MultipartFile excelFile, HttpServletRequest request) {
        List<WorkBotChat> workBotChatList = new ArrayList<>();
        ChatResp chatResp = new ChatResp();
        try {
            List<String[]> chatList = POIUtil.readExcel(excelFile);
            for (int i = 0; i < chatList.size(); i++) {
                String[] chat = chatList.get(i);
                WorkBotChat workBotChat = new WorkBotChat();
                workBotChat.setKeyword(chat[0]);
                workBotChat.setResponse(chat[1]);
                workBotChatList.add(workBotChat);
                BotMethodSwitch.chatHashMap.put(chat[0], chat[1]);
            }
        } catch (IOException e) {
            logger.info("读取excel文件失败", e);
            chatResp.setStatus(400);
            chatResp.setErrorMsg("读取excel文件失败");
        }
        if (workBotChatMapper.deleteAll() >= 0 && workBotChatMapper.insertBatch(workBotChatList) >= 1) {
            chatResp.setStatus(200);
            chatResp.setWorkBotChatList(workBotChatList);
            //返回json
            return chatResp;
        }
        chatResp.setStatus(500);
        chatResp.setErrorMsg("数据库错误");
        chatResp.setWorkBotChatList(workBotChatList);
        return chatResp;
    }


    @RequestMapping(value = "setWhiteKey")
    @ResponseBody
    public WhiteKeyResp whiteList(@RequestBody WhiteKeyReq whiteKeyReq) {
        System.out.println(whiteKeyReq.getWhiteKey());
        WhiteKeyResp whiteKeyResp = new WhiteKeyResp();
        if (whiteKeyReq != null && !whiteKeyReq.getWhiteKey().equals("")) {
            try {
                if (whiteKeyListMapper.deleteAll() >= 0) {
                    BotMethodSwitch.whiteList = new ArrayList<>();
                    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(whiteKeyReq.getWhiteKey().getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));
                    String line;
                    StringBuffer strbuf = new StringBuffer();
                    WhiteKeyList whiteKeyList = new WhiteKeyList();
                    while ((line = br.readLine()) != null) {
                        if (!line.trim().equals("")) {
                            BotMethodSwitch.whiteList.add(line);
                            whiteKeyList.setKeyword(line);
                            whiteKeyListMapper.insert(whiteKeyList);
                        }
                    }
                    whiteKeyResp.setStatus(200);
                    whiteKeyResp.setWhiteKeyList(whiteKeyReq.getWhiteKey());
                    return whiteKeyResp;
                }

            } catch (Exception e) {
                e.printStackTrace();
                whiteKeyResp.setStatus(500);
                whiteKeyResp.setErrorMsg("系统出错");
                return whiteKeyResp;
            }

        }
        whiteKeyResp.setStatus(500);
        whiteKeyResp.setErrorMsg("系统出错");
        return whiteKeyResp;

    }


    @RequestMapping(value = "setBlackKey")
    @ResponseBody
    public BlackKeyResp blackList(@RequestBody BlackKeyReq blackKeyReq) {
        BlackKeyResp blackKeyResp = new BlackKeyResp();
        if (blackKeyReq != null && !blackKeyReq.getBlackKey().equals("")) {
            try {
                if (blackKeyListMapper.deleteAll() >= 0) {
                    BotMethodSwitch.blackList = new ArrayList<>();
                    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(blackKeyReq.getBlackKey().getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));
                    String line;
                    BlackKeyList blackKeyList = new BlackKeyList();
                    while ((line = br.readLine()) != null) {
                        if (!line.trim().equals("")) {
                            BotMethodSwitch.blackList.add(line);
                            blackKeyList.setKeyword(line);
                            blackKeyListMapper.insert(blackKeyList);
                        }
                    }
                    blackKeyResp.setStatus(200);
                    blackKeyResp.setBlackKeyList(blackKeyReq.getBlackKey());
                    return blackKeyResp;
                }
            } catch (Exception e) {
                e.printStackTrace();
                blackKeyResp.setStatus(500);
                blackKeyResp.setErrorMsg("系统出错");
                return blackKeyResp;
            }
        }
        blackKeyResp.setStatus(500);
        blackKeyResp.setErrorMsg("系统出错");
        return blackKeyResp;

    }


    @RequestMapping(value = "getAll")
    @ResponseBody
    public GetWorkBotAll getAll() {
        GetWorkBotAll getWorkBotAll = new GetWorkBotAll();
        try {
            getWorkBotAll.setStatus(200);

            getWorkBotAll.setBotMethod(BotMethodSwitch.botMethod);
            getWorkBotAll.setSendMsgOnTime(BotMethodSwitch.sendMsgOnTime);
            getWorkBotAll.setSendMsgOnTimeStr(BotMethodSwitch.sendMsgOnTimeStr);
            getWorkBotAll.setSendMsgStartMin(BotMethodSwitch.sendMsgStartMin);
            getWorkBotAll.setSendMsgTimes(BotMethodSwitch.sendMsgTimes);

            getWorkBotAll.setToken(BotMethodSwitch.token);
            getWorkBotAll.setTokenDayTimes(BotMethodSwitch.tokenDayTimes);

            getWorkBotAll.setWelcome(BotMethodSwitch.welcome);

            getWorkBotAll.setChatToken(BotMethodSwitch.chatToken);
            getWorkBotAll.setChatDayTimes(BotMethodSwitch.chatDayTimes);
            getWorkBotAll.setCheckInToken(BotMethodSwitch.checkInToken);


            getWorkBotAll.setWorkBotChatList(workBotChatMapper.findAll());
            List<BlackKeyList> blackKeyLists = blackKeyListMapper.findAll();
            String blackKeyResp = "";
            for (int i = 0; i < blackKeyLists.size(); i++) {
                blackKeyResp += blackKeyLists.get(i).getKeyword();
                blackKeyResp += "\r\n";
            }
            getWorkBotAll.setBlackKeylist(blackKeyResp);

            List<WhiteKeyList> whiteKeyLists = whiteKeyListMapper.findAll();
            String whiteKeyResp = "";
            for (int i = 0; i < whiteKeyLists.size(); i++) {
                whiteKeyResp += whiteKeyLists.get(i).getKeyword();
                whiteKeyResp += "\r\n";
            }
            getWorkBotAll.setWhiteKeyList(whiteKeyResp);
            return getWorkBotAll;
        } catch (Exception e) {
            getWorkBotAll.setStatus(500);
            getWorkBotAll.setErrorMsg("系统错误");
            return getWorkBotAll;
        }
    }

    @RequestMapping(value = "welcome")
    @ResponseBody
    public WelcomeResp welcome(@RequestBody WelcomeReq welcomeReq) {
        WelcomeResp welcomeResp = new WelcomeResp();
        if (welcomeReq != null && welcomeReq.getWelcome() != null && !welcomeReq.getWelcome().equals("")) {
            BotMethodSwitch.welcome = welcomeReq.getWelcome();
            workBotService.updateDaoWorkBotInfo();

            welcomeResp.setStatus(200);
            welcomeResp.setWelcome(welcomeReq.getWelcome());
            return welcomeResp;
        } else {
            welcomeResp.setStatus(400);
            welcomeResp.setErrorMsg("请输入非空字符");
            return welcomeResp;
        }
    }

    @RequestMapping(value = "openRedPaper")
    @ResponseBody
    public OpenRedPaperResp openRedPaperResp(@RequestBody OpenRedPaperReq openRedPaperReq) {
        OpenRedPaperResp openRedPaperResp = new OpenRedPaperResp();
        if (openRedPaperReq != null && openRedPaperReq.getAmount() > 0 && !openRedPaperReq.getTokenName().equals("") && openRedPaperReq.getRewardTotal() > 0) {
            if (ProjectBotImpl.getWorkBot().openRed(openRedPaperReq.getTokenName(), openRedPaperReq.getAmount(), openRedPaperReq.getRewardTotal())) {
                openRedPaperResp.setStatus(200);
                openRedPaperResp.setTokenName(openRedPaperReq.getTokenName());
                openRedPaperResp.setAmount(openRedPaperReq.getAmount());
                openRedPaperResp.setRewardTotal(openRedPaperReq.getRewardTotal());

                BotMethodSwitch.tokenName = openRedPaperReq.getTokenName();
                BotMethodSwitch.amount = openRedPaperReq.getAmount();
                BotMethodSwitch.rewardTotal = openRedPaperReq.getRewardTotal();

                workBotService.updateDaoWorkBotInfo();
                return openRedPaperResp;
            } else {
                openRedPaperResp.setStatus(400);
                openRedPaperResp.setErrorMsg("此口令的红包还未领取完");
                return openRedPaperResp;
            }
        } else {
            openRedPaperResp.setStatus(400);
            openRedPaperResp.setErrorMsg("输入参数有误");
            return openRedPaperResp;
        }

    }

    @RequestMapping(value = "getRedPaper")
    @ResponseBody
    public OpenRedPaperResp getRedPaper() {
        OpenRedPaperResp openRedPaperResp = new OpenRedPaperResp();
        openRedPaperResp.setStatus(200);
        openRedPaperResp.setRewardList(rewardMapper.findAll());
        HashMap<String, RedPaperCount> redPaperCountHashMap = new HashMap<>();
        List<RewardUser> list = rewardUserMapper.findAll();
        for (int i = 0; i < list.size(); i++) {
            RedPaperCount redPaperCount = new RedPaperCount();
            //没有找到
            if (!redPaperCountHashMap.containsKey(list.get(i).getUserid())) {
                redPaperCount.setTelegrameId(Integer.parseInt(list.get(i).getUserid()));
                redPaperCount.setTelegramName(list.get(i).getUsername());
                redPaperCount.setRedPaperCount(1);
                redPaperCount.setTokenCount(list.get(i).getReward());
                redPaperCountHashMap.put(list.get(i).getUserid(), redPaperCount);
            } else {
                redPaperCount = redPaperCountHashMap.get(list.get(i).getUserid());
                redPaperCount.setRedPaperCount(redPaperCount.getRedPaperCount() + 1);
                redPaperCount.setTokenCount(redPaperCount.getTokenCount() + list.get(i).getReward());
            }
        }
        openRedPaperResp.setRedPaperCount(redPaperCountHashMap);
        openRedPaperResp.setRewardTotal(BotMethodSwitch.rewardTotal);
        openRedPaperResp.setAmount(BotMethodSwitch.amount);
        openRedPaperResp.setTokenName(BotMethodSwitch.tokenName);

        return openRedPaperResp;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null)//root application context 没有parent，他就是老大.
        {
            try {
                workBotService.initHashMap();
                workBotService.updateWorkBotInfo(workBotInfoMapper.selectByPrimaryKey(1));
                workBotService.updateChatList(workBotChatMapper.findAll());
                workBotService.updateBlackKeyList(blackKeyListMapper.findAll());
                workBotService.updateWhiteKeyList(whiteKeyListMapper.findAll());

                WorkBot.usersMapper = this.usersMapper;
                WorkBot.inviteRewardMapper = this.inviteRewardMapper;
                WorkBot.rewardMapper = this.rewardMapper;
                WorkBot.rewardUserMapper = this.rewardUserMapper;
                WorkBot.guessMapper = this.guessMapper;
                WorkBot.guessUserMapper = this.guessUserMapper;
                WorkBot.telegramUserMapper = this.telegramUserMapper;
                WorkBot.chatTokenMapper = this.chatTokenMapper;
                WorkBot.checkInMapper = this.checkInMapper;

                BotMethodSwitch.adName.add("威信");
                BotMethodSwitch.adName.add("微信");
                BotMethodSwitch.adName.add("电报");
                BotMethodSwitch.adName.add("拉人");
                BotMethodSwitch.adName.add("软件");
                BotMethodSwitch.adName.add("定制");
                BotMethodSwitch.adName.add("V信");
                BotMethodSwitch.adName.add("v信");

                File directory = new File("");
                String author = directory.getAbsolutePath();//绝对路径;
                WorkBotController.imgPath = author + "/img";
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @RequestMapping(value = "guessPhoto", method = RequestMethod.POST)
    @ResponseBody
    public String guess(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        // 上传成功或者失败的提示
        String msg = "";
        this.fileName = (WorkBot.guessMapper.selectNum() + 1) + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."), file.getOriginalFilename().length());
        if (FileUtils.upload(file, imgPath, fileName)) {
            msg = "上传成功！";
        } else {
            msg = "上传失败！";
        }
        return msg;
    }

    @RequestMapping(value = "openGuess", method = RequestMethod.POST)
    @ResponseBody
    public String openGuess(@RequestBody OpenGuessReq openGuessReq) {

        if (openGuessReq != null&&openGuessReq.getDuration()>0&&!openGuessReq.getAnswer().equals("")&&openGuessReq.getQuestion()!=null) {
            try {
                List<String> answer = new ArrayList<>();
                int i = 0;
                BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(openGuessReq.getAnswer().getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));
                String line;
                StringBuffer strbuf = new StringBuffer();
                while ((line = br.readLine()) != null) {
                    if (!line.trim().equals("")) {
                        answer.add(line);
                    }
                }
                ProjectBotImpl.getWorkBot().openGussing(new File(this.imgPath+"/"+this.fileName), openGuessReq.getQuestion(), openGuessReq.getTokenTotal(),
                        openGuessReq.getTokenTimes(), answer, new Date(new Date().getTime()+new Double(openGuessReq.getDuration()*1000*60*60).intValue()));

                return "{\"msg\":\"开启成功\"}";
            } catch (Exception e) {
                e.printStackTrace();
                return "{\"msg\":\"失败，参数有误\"}";
            }
        }
        return "{\"msg\":\"失败，系统出错\"}";
    }

    @RequestMapping(value = "sendGuess")
    @ResponseBody
    public String sendGuess(HttpServletRequest httpServletRequest) {
        String guess = httpServletRequest.getParameter("guessId");
        int gueeId = 0;
        if (guess != null && !guess.equals("")) {
            gueeId = Integer.parseInt(guess);
        }
        if(gueeId!= 0){
            ProjectBotImpl.getWorkBot().sendGuess(gueeId);
            return "发送成功";
        }else {
            return "发送失败";
        }
    }

    @RequestMapping(value = "closeGuess")
    @ResponseBody
    public String closeGuess(HttpServletRequest httpServletRequest){
        String answer = httpServletRequest.getParameter("answer");
        String guess = httpServletRequest.getParameter("guessId");
        int guessId =0 ;
        if(answer!=null&&guess!=null){
            guessId = Integer.parseInt(guess);
            if(guessId!=0){
                ProjectBotImpl.getWorkBot().closeGuessing(guessId,answer);
                return "结算成功";
            }
        }
        return "结算失败";
    }

    @RequestMapping(value = "getGuess")
    @ResponseBody
    public OpenGuessResp getGuess(){
        OpenGuessResp guessResp = new OpenGuessResp();
        List<Integer> guessIdList = BotMethodSwitch.guessId;
        List<Guess> guessList = WorkBot.guessMapper.findAll();
        List<Guess> guessNow = new ArrayList<>();
        List<Guess> guessEnd = new ArrayList<>();
        for(int i=0; i<guessList.size(); i++){
            if(guessIdList.contains(guessList.get(i).getId())){
                guessNow.add(guessList.get(i));
            }else {
                guessEnd.add(guessList.get(i));
            }
        }
        guessResp.setStatus(200);
        guessResp.setGuessEnd(guessEnd);
        guessResp.setGuessNow(guessNow);
        return guessResp;
    }

    @RequestMapping(value = "chatToken")
    @ResponseBody
    public ChatTokenResp chatToken(@RequestBody ChatTokenReq chatTokenReq){
        ChatTokenResp chatTokenResp = new ChatTokenResp();
        if(chatTokenReq!=null&&chatTokenReq.getChatToken()>=0&&chatTokenReq.getChatDayTimes()>=0){
            BotMethodSwitch.chatToken = chatTokenReq.getChatToken();
            BotMethodSwitch.chatDayTimes = chatTokenReq.getChatDayTimes();
            workBotService.updateDaoWorkBotInfo();

            chatTokenResp.setStatus(200);
            chatTokenResp.setChatToken(chatTokenReq.getChatToken());
            chatTokenResp.setChatDayTimes(chatTokenReq.getChatDayTimes());
            return chatTokenResp;
        }
        chatTokenResp.setStatus(400);
        chatTokenResp.setErrorMsg("输入空参数");
        return chatTokenResp;
    }

    @RequestMapping(value = "checkIn")
    @ResponseBody
    public CheckInResp checkIn(@RequestBody CheckInReq checkInReq){
        CheckInResp checkInResp = new CheckInResp();
        if(checkInReq!=null&&checkInReq.getCheckInToken()>=0){
            BotMethodSwitch.checkInToken = checkInReq.getCheckInToken();
            workBotService.updateDaoWorkBotInfo();
            checkInResp.setCheckInToken(checkInReq.getCheckInToken());
            checkInResp.setStatus(200);
            return checkInResp;
        }
        checkInResp.setStatus(400);
        checkInResp.setErrorMsg("请求参数为空");
        return checkInResp;
    }
}
